import User from "../../model/user"
import { appointWithMeGrid, myAppointGrid, myProvideGird, mySeekGrid } from "../../config/grid";
import Order from "../../model/Order";
import roleType from "../../enum/role-type";
import Service from "../../model/service";
import serviceType from "../../enum/service-type";
// pages/my/my.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:{
      avatarUrl:'../../images/logo.png',
      nickName:'点击授权登录'
    },
    // 宫格配置
    // 预约我的宫格
    appointWithMeGrid: appointWithMeGrid,
    // 我的预约宫格
    myAppointGrid: myAppointGrid,
    // 我在提供宫格
    myProvideGird: myProvideGird,
    // 正在找宫格
    mySeekGrid: mySeekGrid,

    appointWithMessageStatus: null,
    myAppointStatus: null,

    provideServiceStatus: null,
    seekServiceStatus:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
     const userInfo = User.getUserInfoByLocal();
     if(userInfo){
        this.setData({
          userInfo
        })

        this._getOrderStatus()
       this._getServiceStatus()
     }
    //  console.log(userInfo);
   
  },

  async _getOrderStatus(){
    const appointWithMessageStatus = Order.getOrderStatus(roleType.PUBLISHER);
    const myAppointStatus = Order.getOrderStatus(roleType.CONSUMER);

    this.setData({
      appointWithMessageStatus: await appointWithMessageStatus,
      myAppointStatus: await myAppointStatus
    })

  },

  async _getServiceStatus(){
     const provideServiceStatus = Service.getServiceStatus(serviceType.PROVIDE);
     const seekServiceStatus = Service.getServiceStatus(serviceType.SEEK);

     this.setData({
      provideServiceStatus: await provideServiceStatus,
      seekServiceStatus: await seekServiceStatus
     })
  },
  
  handleToLogin(){
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})